// components/actionSheet/actionSheet.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    dialogStatus: Boolean,
    price: Number,
    url: String,
    goodsNumber: Number,
    bottom: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    count: 1
  },

  /**
   * 组件的方法列表
   */
  methods: {
    openActionSheet() {
      this.triggerEvent('dealActionSheet',{
        dialogStatus: true
      })
    },
    hideActionSheet() {
      // this.setData({
      //   dialogStatus: false
      // })
      this.triggerEvent('dealActionSheet', {
        dialogStatus: false
      })
    },
    reduce() {
      if(this.data.count > 1) {
        this.setData({
          count: --this.data.count
        })
      }else {
        this.setData({
          count: 1
        })
      }
    },
    add() {
      if (this.data.count >= this.data.goodsNumber) {
        this.setData({
          count: this.data.goodsNumber
        })
        wx.showToast({
          title: '购买商品达到库存上限',
          icon: 'none'
        })
        return;
      }
      this.setData({
        count: ++this.data.count
      })
    },
    previewImage() { //预览图片
      wx.previewImage({
        current: this.data.url,
        urls: [this.data.url]
      })
    }
  }
})
